<!DOCTYPE html>
<html>
#{include file="header.html"}#
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-sm-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5><i class="fa fa-home"></i>字典管理</h5>
<div class="ibox-tools"><a href="?" class="btn btn-xs btn-danger"><i class="fa fa-refresh"></i>刷新</a> </div>
</div>
<div class="ibox-content">
<form id="pagerForm" method="post"  class="form-inline">
<div class="col-sm-3 m-b-xs"> <a class="btn btn-info" href="#{$smarty.const.ACT}#/crm/CstDict/cst_dict_add/">添加数据</a> <a class="btn btn-danger batch_operation" href="#" data-act="del">批量删除</a> 
<!--<div class="btn-group">
                <button data-toggle="dropdown" class="btn btn-danger dropdown-toggle">批量操作 <span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="javascript:void(0)" class="batch_operation" data-act="del">批量删除</a></li>
                </ul>
              </div>--> 
</div>
<div class="col-sm-9 m-b-xs text-right">
<div class="form-group text-left">
<select data-placeholder="选择分类..." name="typetag" class="chosen-select" style="width: 200px;" tabindex="2">
<option value="">请选分类字典</option>

                  
						#{foreach from=$typelist key=k item=v}#
							
                  
<option value="#{$v.typetag}#" hassubinfo="true">#{$v.typename}#</option>

                  
						#{/foreach}#
						
                
</select>
</div>
<div class="form-group">
<input type="text" name="name" placeholder="输入搜索名称" class="form-control">
</div>
<!--<div class="btn-group">
                <button data-toggle="dropdown" class="btn  dropdown-toggle"><span class="caret"></span></button>
                <div class="dropdown-menu">
                  <div class="ibox-content">
                    <div class="form-group">
                      <label>标识</label>
                      <input type="text" name="typetag" placeholder="标识" class="form-control">
                    </div>
                    <div class="form-group">
                      <button type="button" class="btn btn-primary btn-xs btn-block ajaxSearchForm"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                  </div>
                </div>
              </div>-->
<div class="input-group"> <span class="">
<button type="button" class="btn btn-primary ajaxSearchForm"><i class="fa fa-search"></i> 搜索</button>
</span> </div>
</div>
</form>
</div>
<div class="ibox-content">
<table class="table table-hover sorttable 07fly-table" width="100%">
<thead>
<tr>
<th width="22"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
<th width="50">编号</th>
<th width="120">字典名称</th>
<th width="120">分类名称</th>
<th width="120">调用标识</th>
<th width="150" orderField="by_adt" class="sort-filed"><span>排序</span></th>
<th width="120">是否启用</th>
<th>操作</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot class="ibox-content">
<tr>
<td colspan="8" align="center"></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
<script id="tableListTpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><input name="dict_id" class="checkboxCtrlId" value="<%=list[i]['dict_id']%>" type="checkbox"></td>
		<td><%=list[i]['dict_id']%></td>
		<td><input type="text" name="name" value="<%=list[i]['name']%>" class="form-control w150 modify_name" data-id="<%=list[i]['dict_id']%>"></td>
		<td><%=list[i]['typename']%></td>
		<td><%=list[i]['typetag']%></td>
		<td><input type="text" name="sort" value="<%=list[i]['sort']%>" class="form-control w50 modify_sort" data-id="<%=list[i]['dict_id']%>" size="5"></td>
		<td>
		  <div class="onoffswitch">
       		<input type="checkbox" class="onoffswitch-checkbox" data-id="<%=list[i]['dict_id']%>"  id="dict_id_<%=list[i]['dict_id']%>"  <%if(list[i]['visible']==1){%> checked  <%}%>  >
	   		<label class="onoffswitch-label" for="dict_id_<%=list[i]['dict_id']%>"> 
	   			<span class="onoffswitch-inner"></span> 
				 <span class="onoffswitch-switch"></span> 
			 </label>
      	</div>
		</td>
		<td width='10'>
			<div class="btn-group">
				<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">操作 <span class="caret"></span></button>
				<ul class="dropdown-menu">
					<li><a href="#{$smarty.const.ACT}#/crm/CstDict/cst_dict_modify/dict_id/<%=list[i]['dict_id']%>/">修改</a></li>
					<li><a href="javascript:void(0)" class="single_operation" data-id="<%=list[i]['dict_id']%>" data-act="del">删除</a></li>
				</ul>
			</div>
		</td>
	</tr>
<% } %>
</script> 
<!-- 自定义js --> 
<script src="#{$smarty.const.APP}#/View/template/js/content.js?v=1.0.0"></script> 
<script>
var ajaxUrl='#{$smarty.const.ACT}#/crm/CstDict/cst_dict_json/';
$(document).ready(function () {
	
$('.chosen-select').chosen({search_contains: true});
$('.chosen-select').chosen().change(function(){
	ajaxSearchFormData = $("form").serialize();
	turnPage(1);
});
		turnPage(1);//页面加载时初始化分页

		$("body").on("click", ".batch_operation", function() {
		batch_act =$(this).attr("data-act")
		var chk_value =[]; 
    	$("tbody input[class='checkboxCtrlId']:checked").each(function(){ 
        chk_value.push($(this).val()); 
		}); 
		dict_id_txt=chk_value.join(",");
		if(batch_act=="del"){
			act_url="#{$smarty.const.ACT}#/crm/CstDict/cst_dict_del/";
		}
    //alert(chk_value.length==0 ?'你还没有选择任何内容！':chk_value); 
		$.ajax({
			type: "POST",
			url: act_url,
			data:{"dict_id":dict_id_txt},
			dataType:"json",
			success: function(data){
				if(data.statusCode=='200'){
					layer.msg('操作成功', {icon: 1});
					turnPage(1);
				}
			},
			complete: function () {//完成响应
			}
		});
	});
	
	$("body").on("click", ".single_operation", function() {
		dict_id =$(this).attr("data-id");
		single_act =$(this).attr("data-act")
		if(single_act=="del"){
			act_url="#{$smarty.const.ACT}#/crm/CstDict/cst_dict_del/";
		}
		$.ajax({
			type: "POST",
			url: act_url,
			data:{"dict_id":dict_id},
			dataType:"json",
			success: function(data){
				if(data.rtnstatus=='success'){
					layer.msg('操作成功', {icon: 1}); 
					turnPage(1);
				}
			}
		});
	});

	$("body").on("click", ".onoffswitch-checkbox", function() {
			dict_id =$(this).attr("data-id")
			ischecked=$(this).prop('checked');
			if(ischecked){
			   visble='1';
			}else{
				visble='0';
			}
			$.ajax({
				type: "POST",
				url: "#{$smarty.const.ACT}#/crm/CstDict/cst_dict_modify_visible/",
				data:{"visble":visble,"dict_id":dict_id},
				dataType:"json",
				success: function(data){
					if(data.statusCode=='200'){
						layer.msg('操作成功', {icon: 1});   
					}
					log(data.statusCode);
				}
			});
		});
	$("body").on("blur", ".modify_sort", function() {
		dict_id	=$(this).attr("data-id")
		sort=$(this).val();
		$.ajax({
			type: "POST",
			url: "#{$smarty.const.ACT}#/crm/CstDict/cst_dict_modify_sort/",
			data:{"sort":sort,"dict_id":dict_id},
			dataType:"json",
			success: function(data){
				if(data.statusCode=='200'){
					layer.msg('操作成功', {icon: 1});   
				}
				log(data.statusCode);
			}
		});
	});	
	$("body").on("blur", ".modify_name", function() {
		dict_id	=$(this).attr("data-id")
		name=$(this).val();
		$.ajax({
			type: "POST",
			url: "#{$smarty.const.ACT}#/crm/CstDict/cst_dict_modify_name/",
			data:{"name":name,"dict_id":dict_id},
			dataType:"json",
			success: function(data){
				if(data.statusCode=='200'){
					layer.msg('操作成功', {icon: 1});   
				}
				log(data.statusCode);
			}
		});
	});	
});
</script>
</body>
</html>
